﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using UTable.Input;
using System.Windows;
using UTable.Input.MultiTouch;
using UTable.Objects;

namespace UTable.Input2
{
    public class Window7MTProvider : IInputProvider
    {
        Window window;

        public void Initialize(UTable.Objects.UApplication context)
        {
            window = context.MainWindow;
            window.TouchDown += new EventHandler<System.Windows.Input.TouchEventArgs>(window_TouchDown);
            window.TouchMove += new EventHandler<System.Windows.Input.TouchEventArgs>(window_TouchMove);
            window.TouchUp += new EventHandler<System.Windows.Input.TouchEventArgs>(window_TouchUp);
            System.Windows.Input.Mouse.OverrideCursor = System.Windows.Input.Cursors.None;
        }

        void window_TouchUp(object sender, System.Windows.Input.TouchEventArgs e)
        {
            FingerEventArgs f = new FingerEventArgs();
            f.FingerID = e.TouchDevice.Id;
            f.Position = e.GetTouchPoint(window).Position;
            f.GlobalPosition = e.GetTouchPoint(window).Position;
            f.EventType = FingerEventType.FINGER_UP_EVENT;
            MultiTouchEventArgs m = new MultiTouchEventArgs(0);
            m.FingerEvents.Add(f);
            if (InputTriggered != null)
                InputTriggered(m);
        }

        void window_TouchMove(object sender, System.Windows.Input.TouchEventArgs e)
        {
            FingerEventArgs f = new FingerEventArgs();
            f.FingerID = e.TouchDevice.Id;
            f.Position = e.GetTouchPoint(window).Position;
            f.GlobalPosition = e.GetTouchPoint(window).Position;
            f.EventType = FingerEventType.FINGER_MOVE_EVENT;
            MultiTouchEventArgs m = new MultiTouchEventArgs(0);
            m.FingerEvents.Add(f);
            if (InputTriggered != null)
                InputTriggered(m);
        }

        void window_TouchDown(object sender, System.Windows.Input.TouchEventArgs e)
        {
            FingerEventArgs f = new FingerEventArgs();
            f.FingerID = e.TouchDevice.Id;
            f.Position = e.GetTouchPoint(window).Position;
            f.GlobalPosition = e.GetTouchPoint(window).Position;
            f.EventType = FingerEventType.FINGER_DOWN_EVENT;
            MultiTouchEventArgs m = new MultiTouchEventArgs(0);
            m.FingerEvents.Add(f);
            if (InputTriggered != null)
                InputTriggered(m);
        }

        public event InputEventHandler InputTriggered;
    }
}
